package demo;

import java.util.concurrent.LinkedBlockingQueue;

public class LinkedBlockingQueuePerformanceTest {
    private static final int QUEUE_SIZE = 1000000;
    private static final int NUM_THREADS = 4;

    public static void main(String[] args) throws InterruptedException {
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);

        Thread[] threads = new Thread[NUM_THREADS];
        for (int i = 0; i < NUM_THREADS; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < QUEUE_SIZE / NUM_THREADS; j++) {
                    queue.offer(j);
                }
            });
        }

        long start = System.currentTimeMillis();
        for (Thread thread : threads) {
            thread.start();
        }

        for (Thread thread : threads) {
            thread.join();
        }
        long end = System.currentTimeMillis();

        System.out.printf("Elapsed time: %dms%n", end - start);
    }
}